package com.ruoyi.business.dto;

import org.springframework.web.multipart.MultipartFile;

import java.io.*;

public class PdfMultipartFile implements MultipartFile {
    private final byte[] content;
    private final String name;
    private final String contentType;

    public PdfMultipartFile(ByteArrayOutputStream pdfOutputStream, String filename) {
        this.content = pdfOutputStream.toByteArray();
        this.name = filename;
        this.contentType = "application/pdf";
    }

    // 实现 MultipartFile 接口方法（同网络URL方案中的示例）
    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getOriginalFilename() {
        return name;
    }

    @Override
    public String getContentType() {
        return contentType;
    }

    @Override
    public boolean isEmpty() {
        return content.length == 0;
    }

    @Override
    public long getSize() {
        return content.length;
    }

    @Override
    public byte[] getBytes() {
        return content;
    }

    @Override
    public InputStream getInputStream() {
        return new ByteArrayInputStream(content);
    }

    @Override
    public void transferTo(File dest) throws IOException {

    }
}
